﻿using System;
using System.Windows;

namespace KPM.Common.DragHelpers
{
    public abstract class DragDefinition : DependencyObject
    {
        private Func<bool> canDrag;

        protected DragDefinition()
            : this(null)
        {
        }

        protected DragDefinition(Func<bool> canDrag)
        {
            this.canDrag = canDrag;
        }

        public virtual Func<bool> CanDrag
        {
            get
            {
                return this.canDrag;
            }
        }

        public CanvasDragType DragType { get; set; }

        protected Point StartPosition { get; private set; }

        public void DragStarted(UIElement element, Point startPoint)
        {
            this.StartPosition = startPoint;
            this.HandleDragStarted(element);
        }

        public void OnDragMove(UIElement element, Point currentPoint)
        {
            Point vector = new Point(currentPoint.X - this.StartPosition.X, currentPoint.Y - this.StartPosition.Y);
            this.HandleDragMove(element, currentPoint, vector);
        }

        protected abstract void HandleDragStarted(UIElement element);

        protected abstract void HandleDragMove(UIElement element, Point currentPoint, Point overallMovement);
    }
}